<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>${aier_title}</title>
<meta content="${aier_keywords}" name="keywords">
<meta content="${aier_description}" name="description">
<link href="${aier_css_url}jc/chosen.css" rel="stylesheet">
<link rel="stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}/ui.css" />
<link rel="stylesheet" href="${aier_css_url}comm/text.css" />
<link rel="stylesheet" href="${aier_css_url}b.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}comm/fb.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/arrayList.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}comm/text.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/afu.js"></script>

<title>天天育儿</title>
</head>
<style type="text/css">
	.input_opacity{
	    filter:alpha(opacity=0); -moz-opacity:0; opacity: 0;
	}
	.input_hidden{
	    visibility: hidden;
	}
</style>
<body style="background-color: #EEF2FB;">
    
    <div style="background-color: #EEF2FB;width: 100%;height: 700px; ">	
		<div id="tabs">
			<ul>
				<li><a href="#tabs-1">天天育儿</a></li>
			</ul>
			<div id="tabs-1" style="height: 500px;">
			    <button onclick="history.go(-1);" style="margin-top: -10px;margin-left: 200px;"
                    class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                    role="button" aria-disabled="false">
                    <span class="ui-button-text">返回</span>
                </button>
				<div class="d_content">
	                   <div class="d_scnOut">
	                       <div class="d_scname" style="*margin-left: -200px;">宝宝天数</div>
	                       <div class="d_sctext">
	                           <input id="days" type="text" class="txt_scname" />
	                       </div>
	                   </div>
	                   <div class="d_scnOut">
                           <div class="d_scname" style="*margin-left: -200px;">宝宝图片</div>
                           <div class="d_sctext">
	                           <input type="file" id="file" name="file" onchange="txt_path.value=this.value" 
	                                style="width: 74px;height: 36px; margin-top: -3px; margin-left: 13px;
	                                font-size: 14px;font-family: 新宋体,宋体,微软雅黑,Lucida Grande,Lucida Sans,Arial,sans-serif;
	                                position:absolute; z-index: 2;">    
		                        <button id="b_selfile"
		                            style="width: 86px;margin-left: -68px; margin-top: -3px;" 
		                            class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
		                            role="button" aria-disabled="false">
		                            <span class="ui-button-text">选择图片</span>
		                        </button>
		                        <div class="d_sctext" style="margin-left: 115px;margin-top: -28px;">
			                        <input type="text" id="txt_path" class="txt_scname">
			                        <button onclick="loadImage()" style="margin-top: -38px;margin-left: 200px; width: 60px;"
	                                    class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
	                                    role="button" aria-disabled="false">
	                                    <span class="ui-button-text">上传</span>
                                    </button>
			                    </div>
                           </div>
                       </div>
                       <div>
                           <img id = "image" width="150" height="150" style="margin-left: -600px;">
                       </div>
	                   <div class="d_scnOut">
	                       <div class="d_scname" style="*margin-left: -200px;">育儿内容</div>
	                       <div class="d_sctext">
	                           <textarea id="content" rows="13" cols="55" class="txt_scname"></textarea>
	                       </div>
	                   </div>
	                   <button id="b_siCreate"
	                        class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
	                        role="button" aria-disabled="false"
	                        style="margin-top: 190px;margin-left: -600px;" onclick="create();">
	                        <span class="ui-button-text">新增</span>
	                    </button>
	           </div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
    var spid;
    var imageName;
	$("#tabs").tabs();
	$(document).ready(function() {
        //判断是否是ie浏览器， 在IE下document.all值为1，而其他浏览器下的值为0；
        var flag = document.all ? 'IE' : 'others';
        if (flag == 'IE') {
            $("#file").addClass("input_opacity");
            $("#file").removeClass("input_hidden");
        } else {
            $("#file").addClass("input_hidden");
            $("#file").removeClass("input_opacity");
            //上传文件按钮模拟点击
            $("#b_selfile").click(function() {
                $("#file").click();
            });
        }
         
    });
    function loadImage() {
        var filename = $("#txt_path").val();
        if (filename.indexOf("\\")) {
            filename = filename.split("\\")[filename.split("\\").length-1];
        }
        try {
            $.ajaxFileUpload({
                url : "${aier_url}${aier_urijs}parenting_uploadImage${aier_suffix}?filename="+filename,
                secureuri : false,
                fileElementId : 'file',
                dataType : 'json',
                success : function(data, status) {
                    if (1 == data.s) {
                        $().message("上传成功");
                        imageName = data.filename;
                        $("#txt_path").val("");
                        $("#image").attr("src",data.imgUrl+imageName);
                    } else {
                        $().message(data.se);
                    }
                    
                },
                error : function(data, status, e) {
                    $().message("上传失败");
                }
            });
        } catch (e) {
            $().message("服务器连接超时");
        }
    }
    
    function create() {
        var days = $("#days");
        var daysVal = days.val();
        var pattern = new RegExp(/^[0-9]{0,6}$/);    
        var isnum = pattern.exec(daysVal);
        if(isnull(isnum)){
            days.addClass("ui-state-error");
            $().message("请输入正确的数字!");
            days.focus();
            return;
        } else {
            days.removeClass("ui-state-error");
        }
        var content = $("#content");
        var contentVal = content.val();
        
        if (isnull(contentVal)
                || contentVal.length > 2000) {
            content.addClass("ui-state-error");
            $().message("育儿内容为1-2000个字符!");
            content.focus();
            return;
        } else {
            content.removeClass("ui-state-error");
        }
        if (isnull(imageName)) {
            $().message("请上传图片");
            return;
        }
        var fun = function(data) {
            if (1 == data.s) {
                $().message("新增成功,您可以继续新增!");
                window.location.href = "${aier_url}${aier_uri}/parenting_create${aier_suffix}";
            } else if (10000 == data.s) {
                $().message(daysVal+"天宝宝的育儿信息已存在，请重新输入!");
                $("#days").focus();
                $("#days").addClass("ui-state-error");
            } else {
                $().message("新增失败,请稍后再试!");
            }
        };
        exeAjax(
                ajaxUrl("${aier_url}${aier_urijs}parenting_create${aier_suffix}"),
                fun, {
                    "days" : daysVal,
                    "content" : contentVal.split("\n").join("<br />"),
                    "filename":imageName
                });
    }
</script>
</html>